package com.zlfund.cat.zjgsmk.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zhy.autolayout.utils.AutoUtils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Created by chenjun on 2017/8/19.
 */

public class RecyclerViewHolder extends RecyclerView.ViewHolder {

    private Map<Integer,View> mViews;
    private int mType;

    public RecyclerViewHolder(View itemView) {
        super(itemView);
        mViews = new HashMap<>();
        AutoUtils.auto(itemView);
    }

    private void addView(int resId,View v){
        mViews.put(resId,v);
    }

    public <T extends View> T getView(int resId,Class<T> clazz){
        View v = null;
        if (mViews.containsKey(resId)){
            v = mViews.get(resId);
        }else {
            v = itemView.findViewById(resId);
            addView(resId,v);
        }
        return (T) v;
    }

    public int getType() {
        return mType;
    }

    public void setListener(int resId, View.OnClickListener l){
        View v;
        if (mViews.containsKey(resId)){
            v = mViews.get(resId);
        }else {
            v = itemView.findViewById(resId);
        }
        v.setOnClickListener(l);
    }

    public void setOnItemClickListener(View.OnClickListener l){
        itemView.setOnClickListener(l);
    }

    public void setType(int mType) {
        this.mType = mType;
    }
}
